package com.cennavi.function;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorDouble;
import com.googlecode.aviator.runtime.type.AviatorLong;
import com.googlecode.aviator.runtime.type.AviatorObject;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author GongXings
 * @createTime 16 11:20
 * @description
 */
@Component
public class KpiFunction extends AbstractFunction {
    public final static String LIST = "list";
    public final static String SUM = new StringBuilder("reduce(").append(LIST).append(",+,0)").toString() ;

    @Override
    /**
     * @param
     * arg1 cost 真实值 (s-mile)*change+pirce
     * arg2 系数
     */
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,AviatorObject arg2) {
        Number real = FunctionUtils.getNumberValue(arg1, env);
        Number num = FunctionUtils.getNumberValue(arg2, env);
        return new AviatorDouble(real.doubleValue()+num.doubleValue());
    }

    @Override
    public String getName() {
        return "kpi";
    }
}